package cn.tedu.luckydrawuser.handler;

import cn.tedu.luckydrawuser.protocol.po.UserLog;
import cn.tedu.luckydrawuser.service.IUserLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static org.springframework.web.reactive.function.BodyInserters.fromPublisher;

@Component
public class UserLogHandler {
    @Autowired
    private IUserLogService userLogService;

    /**
     * ServerResponse：用于代表http响应，包含响应头和响应体信息
     * ServerRequest：用户代表http请求，包含请求头和请求体的访问
     */
    public Mono<ServerResponse> findAll(ServerRequest request){
        Flux<UserLog> all = userLogService.findAll();
        /*
            ServerResponse.ok() 创建一个响应码为200的响应对象
         */
        return ServerResponse.ok().body(fromPublisher(all,UserLog.class));
    }
}
